' Shapes
' This program displays a shape filled with your favorite number.

CLS

' Call GetShape subprogram to get desired number and shape.

CALL GetShape (character$, shape%)   ' pass two arguments to GetShape

PRINT

' Use CASE statement to call the requested subprogram.

SELECT CASE shape%
    CASE 1          ' if shape% = 1, display a triangle
        CALL PrintTriangle (character$)
    CASE 2          ' if shape% = 2, display a rectangle
        CALL PrintRectangle (character$)
    CASE 3          ' if shape% = 3, display a line
        CALL PrintLine (character$)
END SELECT

PRINT
INPUT "Press Return to continueI", dummy$
END

SUB GetShape (symbol$, choice%) STATIC

' The GetShape subprogram prompts the user for a number and a shape
'   and returns them to the main program in the symbol$ and choice%
'   variables.

PRINT "This program prints a collection of numbers in the ";
PRINT "shape you specify."
PRINT
INPUT "What number would you like to use (0-9)?  ", symbol$
PRINT
PRINT "What shape would you like to see?"
PRINT
PRINT "    1) Triangle"
PRINT "    2) Rectangle"
PRINT "    3) Line"
PRINT
   
WHILE (choice% < 1) OR (choice% > 3)        ' prompt until choice% is valid
    INPUT "Shape (1, 2, or 3):  ", choice%
WEND

END SUB   ' subprogram complete--return to the main program

SUB PrintLine (char$) STATIC

' The PrintLine subprogram receives an argument from the main
'   program and uses it to print a line 30 characters long.

length% = 30                 ' set the length of the line at 30 characters

FOR i% = 1 TO length%  ' display the character 30 times
    PRINT char$;            ' use semicolon to print them one after another
NEXT i%

PRINT

END SUB

SUB PrintRectangle (char$) STATIC

' The PrintRectangle subprogram receives an argument from the main
'   program and uses it to print a rectangle 50 characters long by
'   7 characters high.

length% = 50         ' set length of rectangle at 50 characters
height% = 7           ' set height of rectangle at 7 lines

FOR i% = 1 TO height%      ' for each of the 7 rows in the rectangle,
    FOR j% = 1 TO length%  '   display 50 characters one after another
        PRINT char$;
    NEXT j%
    PRINT                  ' print a carriage return after each row
NEXT i%

END SUB

SUB PrintTriangle (char$) STATIC

' The PrintTriangle subprogram receives an argument from the main
'   program and uses it to print an equilateral triangle.  The Tab
'   function moves the cursor to the correct column location.

rows% = 10               ' set the number of rows to 10
left% = rows%           ' use left% to build left side of triangle
right% = rows% + 1   ' use right% to build right side of triangle

FOR rowCount% = 1 TO rows%             ' for each row in the triangle,
    FOR i% = left% TO rows%
        PRINT TAB(i%); char$;                ' display left side of row
    NEXT i%

    FOR i% = rows% + 1 TO right% - 1   ' display right side of row
        PRINT TAB(i%); char$;
    NEXT i%

    PRINT                     ' print carriage return at end of row
    left% = left% - 1     ' first character in next row will start one
    right% = right% + 1  '   space closer to left margin and extend
NEXT rowCount%         '   one space closer to the right margin

END SUB